package com.example.controller;

import com.example.anno.LogOperation;
import com.example.mapper.EmpMapper;
import com.example.pojo.Emp;
import com.example.pojo.EmpQueryParam;
import com.example.pojo.PageResult;
import com.example.pojo.Result;
import com.example.service.EmpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RequestMapping("/emps")
@RestController
public class EmpController {
    private static final Logger log = LoggerFactory.getLogger(EmpController.class);
    @Autowired
    private EmpService empService;
    //条件分页查询员工信息
    @GetMapping
    public Result page(EmpQueryParam empQueryParam){
        log.info("查询员工信息,{}",empQueryParam);
        PageResult<Emp> pageResult= empService.page(empQueryParam);
        return Result.success(pageResult);
    }
    //增加员工基本信息和工作经历
    @LogOperation
    @PostMapping
    public Result save(@RequestBody Emp emp){
        log.info("增加员工信息");
        empService.sava(emp);
        return new Result();
    }
    //批量删除员工基本信息和工作经历
    @LogOperation
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        log.info("删除员工:{}",ids);
        empService.delete(ids);
        return Result.success();
    }
    //根据id查询员工基本信息和工作经历
    @GetMapping("{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("根据id查询员工信息:{}",id);
        Emp emp= empService.getInfo(id);
        return Result.success(emp);
    }
    //修改员工基本信息和工作经历
    @LogOperation
    @PutMapping
    public Result update(@RequestBody Emp emp){
        log.info("修改员工信息:{}",emp);
        empService.update(emp);
        return Result.success();
    }
}
